package com.whalehearing.tingyou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whalehearing.tingyou.domain.HearingImg;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.whalehearing.tingyou.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.whalehearing.tingyou.mapper.HearingImgValueMapper;
import com.whalehearing.tingyou.domain.HearingImgValue;
import com.whalehearing.tingyou.service.IHearingImgValueService;

/**
 * 听力值Service业务层处理
 *
 * @author zengjun-qxm
 * @date 2024-09-18
 */
@Service
public class HearingImgValueServiceImpl extends ServiceImpl<HearingImgValueMapper, HearingImgValue> implements IHearingImgValueService {

    @Autowired
    private HearingImgValueMapper hearingImgValueMapper;

    /**
     * 查询听力值列表
     *
     * @param hearingImgValue 听力值
     * @return 听力值
     */
    @Override
    public List<HearingImgValue> selectHearingImgValueList(HearingImgValue hearingImgValue)
    {
        List<HearingImgValue> hearingImgValueList = hearingImgValueMapper.selectList(buildQueryWrapper(hearingImgValue));
        return hearingImgValueList;
    }


    private LambdaQueryWrapper<HearingImgValue> buildQueryWrapper(HearingImgValue query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<HearingImgValue> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getHearingImgId() != null, HearingImgValue::getHearingImgId, query.getHearingImgId());
        lqw.eq(query.getTestMethod() != null, HearingImgValue::getTestMethod, query.getTestMethod());
        lqw.orderByDesc(HearingImgValue::getCreateTime);
        return lqw;
    }

    /**
     * 新增听力值
     */
    @Override
    public void saveHearingImgValue(List<HearingImgValue> hearingImgValue) {
        for (HearingImgValue data : hearingImgValue) {
            hearingImgValueMapper.insert(data);
        }
    }

}
